using System.Collections.Generic;
using System.Linq;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_BuildList_RT : RT_Node
    {
        public RT_SingleValuePort[] Values_RT;

        public RT_ValueListPort ValueList_RT;

        public Node_BuildList_RT(Node_BuildList sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Values_RT = BuildRTPortArrayFromGroup<RT_SingleValuePort>(EPortIOType.Input, sourceData.Values);

            ValueList_RT = new RT_ValueListPort(EPortIOType.Output, sourceData.ValueList, this);
            ValueList_RT.OnGetValueList = GetValueList;
        }

        public List<AValue> GetValueList(DAG_Executor executor)
        {
            var info = executor.GetExeInfoOfNode(this) as BuildList_Info;
            if (info == null)
            {
                info = new BuildList_Info(Values_RT.Length);
                executor.SetExeInfoOfNode(this, info);
            }
            for (int i = 0; i < Values_RT.Length; i++)
            {
                info.Values[i] = Values_RT[i].GetValue(executor);
            }
            return info.Values;
        }
    }

    public class BuildList_Info : RT_NodeExeInfo
    {
        public List<AValue> Values { get; private set; }

        public BuildList_Info(int valueCount)
        {
            Values = new List<AValue>(valueCount);
            for (int i = 0; i < valueCount; i++)
            {
                Values.Add(null);
            }
        }
    }
}